﻿using System;
using Common.CustomException;
using SpecFlowTfsLinker.Cleaner;

namespace SpecFlowTfsLinker.Entities
{
    [Serializable]
    public class Statement
    {
        private readonly ICleaner _cleaner;

        private Statement(string statement, StatementType statementType)
        {
            if (string.IsNullOrEmpty(statement))
                throw new StatementException(Error.BadStatementFormat(statementType.ToString()));

            _cleaner = new StatementCleaner(statement);
            Value = _cleaner.Clean();
            Type = statementType;
        }

        public string Value { get; private set; }

        public StatementType Type { get; private set; }

        public static Statement Given(string statement)
        {
            return new Statement(statement, StatementType.Given);
        }

        public static Statement When(string statement)
        {
            return new Statement(statement, StatementType.When);
        }

        public static Statement Then(string statement)
        {
            return new Statement(statement, StatementType.Then);
        }
    }
}